package cn.simon.controller;

import cn.simon.model.Users;

import cn.simon.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("userRegister")
public class UserRegisterController {
    @Autowired
    private UsersService usersService;
    @GetMapping("register")
    public String userRegister(){
        return "userRegister";
    }
    @PostMapping("register")
    public String userRegister(HttpServletRequest request){
        String name = request.getParameter("username");
        String password = request.getParameter("userPassword");
        String phone = request.getParameter("userPhone");
        Users users = Users.builder().username(name).userPassword(password).userPhone(phone).build();
        usersService.addUsers(users);
        return "redirect:userLogin";
    }
}
